//
//  MyInfoView.swift
//  ERecycle-Shop
//
//  Created by abb on 16/8/30.
//  Copyright © 2016年 abb. All rights reserved.
//

import UIKit

class MyInfoView: UIView {
    
    var user:User? {
        didSet {
            iconView.sd_setImageWithURL(user?.userImageUrl, forState: .Normal, placeholderImage: UIImage(named: "user_default"), options: .RefreshCached)
            nameLabel.text = user?.nickName
            phoneLael.text = user?.phoneNumber
        }
    }
    
    var clickIconCallBack:((image:UIImage)->())!
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        setupUI()
        backgroundColor = UIColor.tintColor()
    }
    
    func clickIcon() {
        print(#function)
        clickIconCallBack(image: iconView.imageView!.image!)
    }
    private func setupUI() {
        addSubview(iconView)
        addSubview(nameLabel)
        addSubview(phoneLael)
        iconView.snp_makeConstraints { (make) in
            make.centerX.equalTo(self)
            make.size.equalTo(CGSize(width: 70, height: 70))
            make.centerY.equalTo(self).offset(-10)
        }
        nameLabel.snp_makeConstraints { (make) in
            make.top.equalTo(iconView.snp_bottom).offset(10)
            make.centerX.equalTo(self)
        }
        phoneLael.snp_makeConstraints { (make) in
            make.top.equalTo(nameLabel.snp_bottom).offset(10)
            make.centerX.equalTo(self)
        }
        
        iconView.addTarget(self, action: #selector(clickIcon), forControlEvents: .TouchUpInside)
    }

    
    /// 头像view
    private lazy var iconView:UIButton = {
       let btn = UIButton()
        btn.layer.cornerRadius = 50
        btn.layer.masksToBounds = true
        return btn
    }()
//        UIImageView = {
//        let iv = UIImageView()
//        iv.layer.cornerRadius = 37.5
//        iv.layer.masksToBounds = true
//        let singleTap = UITapGestureRecognizer(target: self, action: #selector(clickIcon(_:)))
//        iv.addGestureRecognizer(singleTap)
//        iv.userInteractionEnabled = true
//        iv.add
//        return iv
//    }()
    /// 昵称view
    private lazy var nameLabel:UILabel = UILabel.creatLabel(color: UIColor.whiteColor(), fontSize: 16)
    /// 电话view
    private lazy var phoneLael:UILabel = UILabel.creatLabel(color: UIColor.whiteColor(), fontSize: 14)

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
}
